﻿@{
    ViewBag.Title = "RequireToDeliveryList";
}

@section scripts
{   
    <script src="@Url.Content("~/Scripts/shared/share.js")" type="text/javascript"></script> 
    <script src="@Url.Content("~/Scripts/shared/shown.js")" type="text/javascript"></script>  
    <script src="@Url.Content("~/Scripts/common/gridlayout.js")" type="text/javascript"></script>
    <script src="@Url.Content("~/Scripts/common/export.js")" type="text/javascript"></script>
}
<body>
   <form id="form1" runat="server" method="post" style="height: 100%">
    
    <div class="mini-toolbar" style="padding:2px;border-top:0;border-left:0;border-right:0;"> 
        <table style="width:100%;">
            <tr>
                <td style="width:100%;">
                    <a class="mini-button" id="refresh" iconCls="icon-search" onclick="search" plain="true">刷新</a>
                    <span class="separator"></span>
                    <a class="mini-button" id="sendtodawout" name="sendtodawout" iconCls="icon-new" onclick="sendToDawOut" plain="true">生成配送出库单</a>                
                    <span class="separator"></span>
                    <a class="mini-button" id="export" iconCls="icon-node" onclick="setExportExcel('datagrid1')"plain="true">导出</a>                    
                    <span class="separator"></span>
                    <a class="mini-button" id="close" iconCls="icon-close" onclick="CloseWindow" plain="true">关闭</a>
                </td>
            </tr>
        </table>                
    </div>
    
    <div id = "DivHeader">
        <table style="margin-bottom:4px;">
            <tr>
                <td width ="70px" align="right">单据日期：</td>
                <td width ="310px">
                    @Html.Partial("~/Views/Modular/dxDateRange.cshtml") 
                </td>
                <td width ="70px" align="right">要货门店：</td>
                <td width ="190px">    
                    @Html.Partial("~/Views/Modular/LookupStockInfo.cshtml")  
                </td>
                <td width ="70px" align="right"></td>
                <td width ="150px">
                </td>
            </tr>
            <tr>
                <td width ="70px" align="right">单据编号：</td>
                <td width ="310px">
                    <input name="FBillNo" class="mini-textbox" style="width:295px;"/>
                </td>
                <td width ="70px" align="right">配送门店：</td>
                <td width ="190px">    
                     @Html.Partial("~/Views/Delivery/LookupStockRelevant.cshtml")                      
                </td>
                <td width ="70px" align="right">配送状态：</td>
                <td width ="150px">
                    <input id="comListType" name ="FListType" class="mini-combobox" style="width:100px;" 
                    showNullItem="false" value="1" allowInput="false" align="left" data ="dListType"/>  
                </td>
            </tr>
        </table>
    </div>
    <div class="mini-fit">
        <div id="datagrid1" class="mini-datagrid" style="width:100%;height:50%;" borderStyle="border:1;"pageSize="15"
            url="../Report/GetBillList"
            allowCellSelect="true" allowCellEdit="true" showSummaryRow="true" ondrawsummarycell="onDrawSummaryCell"
            fitColumns="false" sortMode="client" onselectionchanged="onSelectionChanged"
            multiSelect="true">
            <div property="columns">
                <div type="checkcolumn"></div>  
                <div field="FBillNo" width="120" headerAlign="center">单据编号</div>    
                <div field="FDate" name="FDate" width="90px" dateFormat="yyyy-MM-dd" headerAlign="center">单据日期</div> 
                <div field="FQty" name="FQty" width="90" headerAlign="center" align="right" numberFormat="#,0.00">要货数量</div>
                <div field="FAmount" name="FAmount" width="90" headerAlign="center" align="right" numberFormat="#,0.00">合计金额</div>
                <div field="FQty_DawOut" name="FQty_DawOut" width="90" headerAlign="center" align="right" numberFormat="#,0.00">配送数量</div>
                <div field="FQty_DawIn" name="FQty_DawIn" width="90" headerAlign="center" align="right" numberFormat="#,0.00">收货数量</div>
                <div field="FQty_Pra" name="FQty_Pra" width="90" headerAlign="center" align="right" numberFormat="#,0.00">未配送数量</div>                
                <div field="FSetStockName" width="150" headerAlign="center">配送门店</div>
                <div field="FGetStockName" width="150" headerAlign="center">要货门店</div>
                <div field="FUserName" width="80" headerAlign="center">用户名称</div>
                <div field="FCheckDate" name="FCheckDate" width="90px" dateFormat="yyyy-MM-dd" headerAlign="center">审核日期</div> 
                <div field="FRemark" width="120" headerAlign="center">备注</div>    
            </div>
        </div>  
        <div id="datagrid2" class="mini-datagrid" style="width:100%;height:50%;" url="../Report/GetBillView"
            showPager = "false" showPageSize="false" showPageIndex="false" fitColumns="false">
            <div property="columns">            
                <div type="indexcolumn" width="35" headerAlign="center" >序号</div>
                <div field="mFNumber" name="mFNumber" displayField = "mFNumber" width="120" headerAlign="center">商品编码</div>  
                <div field="mFName" name="mFName" width="160" headerAlign="center">商品名称</div>  
                <div field="mFModel" name="mFModel" width="100" headerAlign="center">规格型号</div>
                <div field="mFUnitName" name="mFUnitName" width="50" headerAlign="center">单位</div>
                <div field="mFStockQty" name="mStockQty" width="90" headerAlign="center" align="right">库存数量</div>
                <div field="mFQty" name="mFQty" width="90" headerAlign="center" align="right">要货数量</div>
                <div field="mFQty_DawOut" name="mFQty_DawOut" numberFormat="#,0.00" width="90" headerAlign="center" align="right" summaryType="sum">发货数量</div>
                <div field="mFQty_DawIn" name="mFQty_DawIn" numberFormat="#,0.00" width="90" headerAlign="center" align="right" summaryType="sum">收货数量</div>
                <div field="mFQty_DawOutUn" name="mFQty_DawOutUn" numberFormat="#,0.00" width="90" headerAlign="center" align="right" summaryType="sum">未配送数量</div>
                <div field="mFPrice" name="mFPrice" width="90" numberFormat="#,0.00" headerAlign="center" align="right">配送单价</div>
                <div field="mFAmount" name="mFAmount" numberFormat="#,0.00" width="90" headerAlign="center" align="right" summaryType="sum">合计金额</div>
                <div field="mFCode" name="mFCode" width="120" headerAlign="center">商品条码</div>        
                <div field="mFRemark" name="mFRemark" headerCls="CellLast" width="150" headerAlign="center" >备注</div>
            </div>
        </div>  
    </div>
    <input id="type" name="type" value="@ViewBag.type" type="hidden"/>
    <script type="text/javascript">

        var dListType = [{ "id": "0", "text": "全部" },
                         { "id": "1", "text": "未配送" },
                         { "id": "2", "text": "部分配送" },
                         { "id": "3", "text": "已配送" }]

        mini.parse();
        var form = new mini.Form("form1");
        var grid1 = mini.get("datagrid1");
        var grid2 = mini.get("datagrid2");
        var uID = parent.window.getSystemAppID();
        var hdatatype = $("#type").val();
        var sumFields = "FQty,FAmount,FQty_DawOut,FQty_DawIn,FQty_Pra";

        function FormShown() {
            var nowDate = new Date();
            mini.getbyName("FDate1").setValue(nowDate);
            mini.getbyName("FDate2").setValue(nowDate);
            mini.getbyName("FListType").select(1);
            search();
        }

        function sendToDawOut() {
            var rows = grid1.getSelecteds();
            if (rows.length > 0) {
                mini.confirm("确定要生成配送出库单吗？", "提示",
                    function (action) {
                        if (action == "ok") {
                            SetToDawOut();
                        }
                    }
                );
            }
            else {
                mini.alert("没有选择要生成配送出库单的要货单据!");
            }
        }

        function SetToDawOut() {
            var rows = grid1.getSelecteds();
            var mjson = "[{'FSystemAppID':'" + uID + "',";
            var json = "'bill_list':[";
            for (var i = 0, l = rows.length; i < l; i++) {
                var row = rows[i];
                if (json.length > 20) json = json + ",";
                json = json + '{"KInterID":"' + row.KInterID + '"}';
            }
            json = json + "]";
            mjson = mjson + json + "}]";
            $.ajax({
                url: '../Delivery/SetRequireToDelivery',
                data: { mdatajson: mjson },
                type: "post",
                cache: false,
                success: function (txt) {
                    var ret = mini.decode(txt);
                    if (ret.id != -1) {
                        search();
                        mini.showMessageBox({
                            showModal: false, width: 250, title: "提示", iconCls: "mini-messagebox-info",
                            message: ret.Status, timeout: 3000, x: "right", y: "bottom"
                        });
                    }
                    else {
                        mini.alert("异常:" + ret.Status);
                    }
                },
                error: function (xhr) {
                    mini.alert("异常:" + xhr.responseText);
                }
            });
        }

        function search() {
            var cDate1 = mini.getbyName("FDate1").getFormValue();
            var cDate2 = mini.getbyName("FDate2").getFormValue();
            var mListType = mini.getbyName("FListType").getValue();
            var mBillNo = mini.getbyName("FBillNo").getValue();
            var mStockID = mini.getbyName("FRStockID").getValue();
            var FRStockID = mini.getbyName("FStockID").getValue();

            var json = "[{";
            json = json + '"mListType":' + '"' + "1012" + '",';//列表类型
            json = json + '"mSystemAppID":' + '"' + uID + '",';
            json = json + '"mDate1":' + '"' + cDate1 + '",';
            json = json + '"mDate2":' + '"' + cDate2 + '",';
            json = json + '"mCheckFlag":' + '"2",';
            json = json + '"mDataType":' + '"' + mListType + '",';
            json = json + '"mStockID":' + '"' + FRStockID + '",';
            json = json + '"mRStockID":' + '"' + mStockID + '",';
            json = json + '"mBillNo":' + '"' + mBillNo + '"';
            json = json + "}]";

            grid1.load({ mydata: json });
            grid2.setData(null);
            mExportDataUrl = grid1.url;
            mExportDataJson = json;//导出
        }

        function onSelectionChanged(e) {
            var grid = e.sender;
            var record = grid.getSelected();
            if (record) {
                var mListType = mini.getbyName("FListType").getValue();
                grid2.load({ mBillID: record.KInterID, mDataType: "1012", mListType: mListType, mSystemAppID: uID });
            }
            else {
                grid2.setData(null);
            }
        }

    </script>

    </form>
</body>